`
https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/
`

/**
 * @param {number[]} records
 * @return {number}
 */
var takeAttendance = function (records) {
  let left = 0, right = records.length - 1

  while (left <= right) {
    const mid = left + Math.floor((right - left) / 2)
    // 如果当前值和下标相同，说明缺席的在右边，收缩左边界
    if (records[mid] === mid) {
      left = mid + 1
    }
    // 如果当前值和下标不同，说明缺席的在左边，收缩右边界
    else {
      right = mid - 1
    }
  }

  return left
};